/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.content;

import com.jb.web.context.WebContext;
import com.jb.web.renderer.RendererImpl;

import com.jb.faces.component.UIComponent;


public class VideoRenderer extends RendererImpl {
    public StringBuffer renderBegin(WebContext pCtx, UIComponent itemToRender) {
        Video hItem = (Video) itemToRender;
        StringBuffer htmlBuffer = new StringBuffer("");

        htmlBuffer.append("<div ").append(getEditScript(pCtx, hItem))
                  .append(addTagProperty("style", hItem.getStyle(pCtx), null))
                  .append(addTagProperty("class", hItem.getStyleClass(pCtx), null)).append(" >");

        return htmlBuffer;
    }

    public StringBuffer renderChildren(WebContext pCtx, UIComponent itemToRender) {
        Video hItem = (Video) itemToRender;
        String loc = hItem.getSource();
        StringBuffer htmlBuffer = new StringBuffer("");

        if (!isEmptyString(loc) && isVisible(pCtx, hItem)) {
            loc = evaluate(pCtx, hItem, loc);
            htmlBuffer.append("<EMBED ").append(addTagProperty("name", hItem.getId(), null))
                      .append(addTagProperty("src", loc, null))
                      .append(addTagProperty("type", "application/x-mplayer2", null))
                      .append(addTagProperty("ShowControls", hItem.isShowControls() ? "1" : "0", null))
                      .append(addTagProperty("ShowStatusBar", hItem.isShowStatusBar() ? "1" : "0", null))
                      .append(addTagProperty("AutoSize", "" + hItem.isAutoSize(), null))
                      .append(addTagProperty("loop", "" + hItem.isLoop(), null))
                      .append(addTagProperty("EnableContextMenu", hItem.isEnableContextMenu() ? "1" : "0", null))
                      .append(addTagProperty("DisplaySize", hItem.isDisplaySize() ? "1" : "0", null))
                      .append(addTagProperty("WIDTH", hItem.getWidth(), null))
                      .append(addTagProperty("HEIGHT", hItem.getHeight(), null))
                      .append(addTagProperty("PLUGINSPAGE",
                    "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/", null)).append("</EMBED>");
        } else {
            htmlBuffer.append("<img src=\"resources/images/media/Movie24.gif\"")
                      .append(addTagProperty("style", hItem.getStyle(pCtx), null)).append(getEditScript(pCtx, hItem))
                      .append(" />");
        }

        return htmlBuffer;
    }

    public StringBuffer renderEnd(WebContext pCtx, UIComponent itemToRender) {
        return new StringBuffer("&nbsp;</div>");
    }
}
